package com.fanghuaman.common.util;

import com.alibaba.fastjson.JSON;
import com.fanghuaman.common.exception.FanghuamanException;
import com.fanghuaman.model.common.emus.HttpEmus;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.Date;

/**
 * @author shiminghui
 * @date 2024/12/1 17:36
 * @description: TODO
 */
public class SecurityUtil {
    public static User getUser(String UserJsonString) {
        if (UserJsonString == null || "".equals(UserJsonString)) {
            return null;
        }
        User user = null;
        try {
            user = JSON.parseObject(UserJsonString, User.class);
        } catch (Exception e) {
            throw new FanghuamanException(HttpEmus.UNAUTHORIZED);
        }
        if (user == null) {
            return null;
        }
        return user;
    }

    @Data
    @EqualsAndHashCode(callSuper = false)
    public static class User implements Serializable {

        private static final long serialVersionUID = 1L;

        private Long id;

        /**
         * 用户名
         */
        private String username;

        /**
         * 昵称,默认是用户名
         */
        private String nickname;

        /**
         * 密码
         */
        private String password;

        /**
         * 头像图片url
         */
        private String avatar;

        /**
         * 邮箱
         */
        private String email;

        /**
         * 手机号
         */
        private String phone;

        /**
         * 年龄
         */
        private Integer age;

        /**
         * 默认地址
         */
        private String address;

        /**
         * 0是男 1是女 2是未知
         */
        private Integer sex;

        /**
         * 国籍
         */
        private String nationality;

        /**
         * qq
         */
        private String qq;

        /**
         * 微信
         */
        private String wechat;

        /**
         * 创建时间
         */
        private Date createTime;

        /**
         * 更新时间
         */
        private Date updateTime;


    }
}
